<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<base href="<%=basePath%>">
<html lang="zn-cn">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>公共组织</title>
    <link rel="stylesheet" href="css/service.css">
    <link rel="stylesheet" href="css/base.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/base.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/handle.js"></script>
</head>
<body class="ed">
<div class="wrap por ">
    <div class="wrapper3 height_auto" style="padding-bottom: 10px">

        <div class="norecordbox"></div>
        <div class="cardlist_box"></div>
    </div>
</div>
<div class="toast toast_timeout" style="display:none">网络异常，请稍后重试！</div>
<div class="toast toast_error" style="display:none"></div>
<div class="loading" style="display:none">
    <img src="img/loading.gif"></div>
<script type="text/javascript">
    var noMoreOrderText = "<div class='noMoreOrder'></div>";
    var getMoreOrderText = "<div class='getMoreOrder'></div>";
    var currentPage = 1;
    var norecordText = "<div class='norecord'><img src='img/nobindcard.png'><p>你没有加入任何组织哦!</p></div>";
    var carTypeArray = ['<div class="frame_0">框架</div>', '<div class="frame_1">1</div>', '<div class="frame_2">2</div>'];
    $(function () {
        // 获取卡列表的入口
        getCardList();
        $(".cardlist_box").on('click', '.itembtn', function (event) {
            var targetCardNo = $(this).parents(".carditem").attr('data-cardNo');
            window.location.href = "wxmp/yellow/toInfo?oid=" + targetCardNo;
        });
        $(".wrap").on('click', '.getMoreOrder', function (e) {
            getCardList();
        });

    })

    // 获取卡列表
    function getCardList() {
        console.log('step into getCardList()')
        var data = {
            usePager:"true",
            pageNum: currentPage,
            pageSize: 10
        }
        $(".loading").show();
        $.ajax({
            url: $.httpRootPath() + 'rest/yellow/getAllOrg',
            type: 'GET',
            dataType: 'json',
            data: data,
            cache: false,
            timeout: 15000,
            success: function (r) {

                $(".getMoreOrder,.cardlist_box .noMoreProduct").remove();
                console.log(r);
                $(".loading").hide();
                if (r.code != "00") {
                    errorToast(r.msg, 3);
                    return false;
                }
                if (r.data.length == 0) {
                    $(".norecordbox").append(norecordText);
                    return false;
                }
                $("body").append("");

                for (var i = 0; i < r.data.length; i++) {

                    var modCal = 0;
                    var obj = r.data[i],
                        cardNo = obj.id,
                        cardNoFormat = obj.name,
                        vehiclePlate = obj.createTime;
                    cardType = carTypeArray[obj.type];
                    var innerText = "<div class='carditem' data-cardNo=" +
                        cardNo + "><div class='itemtop_out card_bg" +
                        modCal + "'><div class='itemtop'><h2>" + cardNoFormat
                        + "</h2><h3>" + vehiclePlate
                        + "</h3></div></div><div class='itembtn'>组织详情<span><img	src='img/right_arr3.png'></span></div></div>";

                    $(".cardlist_box").append(innerText);

                }
                // 有下一页 显示加载更多的按钮
                if (r.pager.hasNextPage) {
                    $(".cardlist_box").append(getMoreOrderText);
                    currentPage++;
                } else {
                    $(".cardlist_box").append(noMoreOrderText);

                }
            },
            error: function (e) {
                console.log(e);
                $(".loading").hide();
                $(".norecordbox").append(norecordText);
                ajaxErrorEvent(e);

            }
        });
    }
</script>

<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="js/weixin.js"></script>
<script type="text/javascript">
    var jsApiList = ['onMenuShareTimeline', 'onMenuShareAppMessage'];
    getSignature(jsApiList, function () {
        var desc = '点击查看公开组织的列表信息'
        var title = '手机群录微信公众号,轻松找到那个她';
        var fromUser = "${fromUser}" == "" ? GetQueryString("fromUser") : "${fromUser}";
        wx.onMenuShareAppMessage({
            title: title, // 分享标题
            desc: desc, // 分享描述
            link: $.httpRootPath() + 'yellow/toFollowList?fromUser=' + fromUser, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: $.httpStaticPath() + 'common/icon/queryList.png', // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            success: function () {
                // 用户确认分享后执行的回调函数
                console.log("用户分享")
                var data = {
                    fromPage: location.href,
                    fromUser: fromUser,
                    shareType: "onMenuShareAppMessage",
                    content: desc
                };
                addShareRecord(data);
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                console.log("用户取消分享")
            }
        });
        wx.onMenuShareTimeline({
            title: title, // 分享标题
            link: $.httpRootPath() + 'yellow/toFollowList?fromUser=' + fromUser,// 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: $.httpStaticPath() + 'common/icon/queryList.png', // 分享图标
            success: function () {
                var data = {
                    fromPage: location.href,
                    fromUser: fromUser,
                    shareType: "onMenuShareTimeline"
                };
                addShareRecord(data);
            },
        });
    })
</script>
</body>
</html>